Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common
Imports Seuss.EnterpriseLibrary.Types
Imports System.Data

Namespace Seuss.EnterpriseLibrary.DataAccess

    Public Class DAL_Administracion

        Implements IDisposable

#Region "Dispose"

        Private disposedValue As Boolean = False
        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then
                End If
            End If
            Me.disposedValue = True
        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub

#End Region

#Region "Atributos"
        Dim Db As Database
#End Region

#Region "Propiedades"

        ReadOnly Property Database() As Database
            Get
                Return Db
            End Get
        End Property
#End Region

#Region "Constructores"
        Public Sub New()
            Db = DatabaseFactory.CreateDatabase
        End Sub

        Public Sub New(ByVal NewDb As Database)

            Db = NewDb

        End Sub
#End Region

#Region "Metodos: Acceso a Datos"

#Region "Usuarios"
        Public Shared Function getMenu(ByVal DT As DataTable) As String
            Dim strMenu As String = ""

            Dim Items As String = ""

            For i As Integer = 0 To DT.Rows.Count - 1
                Dim item As String
                Dim var As String = DT.Rows(i).Item("cIntJerarquia").ToString
                If var.Length = 4 Then
                    Dim Texto As String = DT.Rows(i).Item("cIntNombre")
                    Dim Objetivo As String = DT.Rows(i).Item("cIntTarget")
                    Dim Url As String = DT.Rows(i).Item("cIntDescripcion")
                    item = "<li class='#'><a href='" & IIf(String.IsNullOrEmpty(Url), "#", Url) & "' target='" & Objetivo & "'><span class='menu-left'></span><span class='menu-mid'>" & Texto & "</span><span class='menu-right'></span></a>"
                    Dim subitems As String = "<div class='sub'><ul>"
                    Dim subs As Boolean = False
                    Dim subitem As String = ""
                    For j As Integer = 0 To DT.Rows.Count - 1
                        If Left(DT.Rows(j).Item("cIntJerarquia").ToString, 4) = var And Len(DT.Rows(j).Item("cIntJerarquia").ToString) = 6 Then
                            Texto = DT.Rows(j).Item("cIntNombre")
                            Objetivo = DT.Rows(j).Item("cIntTarget")
                            Url = DT.Rows(j).Item("cIntDescripcion")
                            subitem = subitem & "<li><a href='" & IIf(String.IsNullOrEmpty(Url), "#", Url) & "' target='" & Objetivo & "'>" & Texto & "</a></li>"
                            subs = True
                        End If
                    Next
                    If subs = True Then
                        subitems = subitems & subitem & "</ul><div class='btm-bg'></div></div>"
                    Else
                        subitems = ""
                    End If
                    item = item & subitems & "</li>"
                    Items = Items & item
                End If
            Next

            strMenu = "<div class='wrapper1'>" & _
            "<div class='wrapper'>" & _
            "<div class='nav-wrapper'>" & _
            "<div class='nav-left'></div>" & _
            "<div class='nav'>" & _
            "<ul id='navigation' style='align:left;'>" & _
            "<li class='#'><a href='../MiSeuss/Default.aspx'><img src='Imagen/Home2.png' border='0' vspace=0 hspace=0/></a></li>" & _
            Items & _
            "</ul>" & _
            "</div>" & _
            "<div class='nav-right'></div>" & _
            "<br><br>" & _
            "</div>" & _
            "</div>" & _
            "</div>" & _
            "</div>"
            strMenu = "<table width='800px' align='left' cellpadding=0 cellspacing=0 border=0><tr><td>" + strMenu + "</td></tr></table>"
            Return strMenu
        End Function

        Public Function Get_User_Validated(ByVal UserName As String, ByVal Password As String) As DbCommand

            If (String.IsNullOrEmpty(UserName) OrElse String.IsNullOrEmpty(Password)) Then
                Return Nothing
            End If

            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_User_Validate")
                Db.AddInParameter(Cmd, "cPerUsuCodigo", System.Data.DbType.String, UserName)
                Db.AddInParameter(Cmd, "cPerUsuClave", System.Data.DbType.String, Password)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
            Return Nothing
        End Function

        Public Function Get_User_Sexo(ByVal cPerCodigo As String) As DbCommand

            If (String.IsNullOrEmpty(cPerCodigo)) Then
                Return Nothing
            End If

            Try
                Dim vsql As String
                vsql = "select isnull(npernatsexo,0) from pernatural where cpercodigo='" + cPerCodigo.ToString + "'"
                Dim Cmd As DbCommand = Db.GetSqlStringCommand(vsql)                
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
            Return Nothing
        End Function

        Public Function Get_CompruebaDatos_To_Book(ByVal cPercodigo As String) As DbCommand
            Dim vsql As String
            vsql = "select cPerCodigo  from chimbote.hades.dbo.persona where cpercodigo='" & cPercodigo.ToString & "'"
            Try
                Dim Cmd As DbCommand = Db.GetSqlStringCommand(vsql.ToString)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
            Return Nothing
        End Function

        Public Function Ins_DatosPersona_To_Book(ByVal cPerCodigo As String) As DbCommand
            Dim vsql As String
            vsql = " insert into chimbote.hades.dbo.persona(cPerCodigo, cPerApellido, cPerApellPat, cPerNombre, dPerNacimiento, nPerTipo, nPerEstado, cUbiGeoCodigo, cperestadobiblio, nUbiGeoCodigo) " & _
                    " select cPerCodigo, cPerApellido, cPerApellPat, cPerNombre, dPerNacimiento, nPerTipo, nPerEstado, cUbiGeoCodigo, cperestadobiblio, nUbiGeoCodigo from persona where cpercodigo='" & cPerCodigo.ToString & "' "
            Try
                Dim Cmd As DbCommand = Db.GetSqlStringCommand(vsql.ToString)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
            Return Nothing
        End Function

        Public Function Get_Permiso_Disponible_By_User(ByVal cPerCodigo As String, _
                                                       ByVal cIntJerarquia As String, _
                                                       ByVal nSisGruCodigo As Long, _
                                                       ByVal nSisGruTipo As Long, _
                                                       Optional ByVal nObjTipo As Long = 1011, _
                                                       Optional ByVal nIntTipo As Long = 0) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_Permiso_Disponible_Get_By_User")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Db.AddInParameter(Cmd, "nIntTipo", System.Data.DbType.Int32, nIntTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_PerUsuGruAcc_By_Persona(ByVal cPerCodigo As String, _
                                      ByVal nSisGruCodigo As Long, _
                                      ByVal nSisGruTipo As Long, _
                                      ByVal nObjCodigo As Long, _
                                      ByVal nObjTipo As Long, _
                                      Optional ByVal cPerCodigoExclude As String = Nothing) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Get")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, nObjCodigo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Db.AddInParameter(Cmd, "cPerCodigoExclude", System.Data.DbType.Int32, cPerCodigoExclude)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_Permiso_By_User(ByVal cPerCodigo As String, _
                                            ByVal cIntJerarquia As String, _
                                            ByVal nSisGruCodigo As Long, _
                                            ByVal nSisGruTipo As Long, _
                                            Optional ByVal nObjTipo As Long = 1011, _
                                            Optional ByVal nIntTipo As Long = 0, _
                                            Optional ByVal cIntDescripcion As String = "") As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_Permiso_Get_By_User")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Db.AddInParameter(Cmd, "nIntTipo", System.Data.DbType.Int32, nIntTipo)
                If cIntDescripcion <> "" Then Db.AddInParameter(Cmd, "cIntDescripcion", System.Data.DbType.String, cIntDescripcion)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_PermisoMenuPerfil_By_User() As DbCommand
            Try
                Dim vsql As String
                vsql = "select *,'_self' as cIntTarget from Interface where nIntClase =1011 and nIntTipo <>0 and cIntJerarquia like '03%' and cIntJerarquia <>'03'"
                Dim Cmd As DbCommand = Db.GetSqlStringCommand(vsql)

                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_Permiso_Nivel_By_User(ByVal cPerCodigo As String, _
                                           ByVal cIntJerarquia As String, _
                                           ByVal nSisGruCodigo As Long, _
                                           ByVal nSisGruTipo As Long, _
                                           Optional ByVal nObjTipo As Long = 1011, _
                                           Optional ByVal nIntTipo As Long = 0, Optional ByVal Vista As Long = 0) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_Permiso_Nivel_Get_By_User")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Db.AddInParameter(Cmd, "nIntTipo", System.Data.DbType.Int32, nIntTipo)
                Db.AddInParameter(Cmd, "Vista", System.Data.DbType.Int32, Vista)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function
        Public Function Get_Permiso_By_PerJuridica(ByVal cPerCodigo As String, _
                                          ByVal cIntJerarquia As String, _
                                          ByVal nSisGruCodigo As Long, _
                                          ByVal nSisGruTipo As Long, _
                                          Optional ByVal nObjTipo As Long = 1011, _
                                          Optional ByVal nIntTipo As Long = 0, Optional ByVal Vista As Long = 0) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_Permiso_Get_By_PerJuridica")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Db.AddInParameter(Cmd, "nIntTipo", System.Data.DbType.Int32, nIntTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_PermisoGeneral_By_Nivel(ByVal cIntJerarquia As String, _
                                                    Optional ByVal nObjTipo As Long = 1011, _
                                                    Optional ByVal nIntTipo As Long = 1) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PermisoGeneral_Get_By_Nivel")
                Db.AddInParameter(Cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(Cmd, "nIntClase", System.Data.DbType.Int32, nObjTipo)
                Db.AddInParameter(Cmd, "nIntTipo", System.Data.DbType.Int32, nIntTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_User_By_Codigo(ByVal cPerCodigo As String) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_User_Get_By_Codigo")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_User_By_Group(ByVal nGruCodigo As Integer, Optional ByVal nObjTipo As Integer = 1004) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_User_Get_By_Grupo")
                Db.AddInParameter(Cmd, "nGruCodigo", System.Data.DbType.Int32, nGruCodigo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_User_Persona_By_Nombres_Exclude_Grupo(ByVal cPerApellido As String, _
                                                                  ByVal cPerNombre As String, _
                                                                  ByVal nGruCodigo As Integer, _
                                                                  ByVal nRowCount As Long, _
                                                                  Optional ByVal nObjTipo As Integer = 1004) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_User_Get_Persona_By_Nombres_Exclude_Grupo")
                Db.AddInParameter(Cmd, "cPerApellido", System.Data.DbType.String, cPerApellido)
                Db.AddInParameter(Cmd, "cPerNombre", System.Data.DbType.String, cPerNombre)
                Db.AddInParameter(Cmd, "nGruCodigo", System.Data.DbType.Int32, nGruCodigo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Db.AddInParameter(Cmd, "RowCount", System.Data.DbType.Int32, nRowCount)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_User(ByVal cPerCodigo As String, _
                                 ByVal cPerUsuCodigo As String, _
                                 ByVal cPerUsuClave As String) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_User_Set")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "cPerUsuCodigo", System.Data.DbType.String, cPerUsuCodigo)
                Db.AddInParameter(Cmd, "cPerUsuClave", System.Data.DbType.String, cPerUsuClave)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_PerUsuGruAcc_Interface(ByVal cPerCodigo As String, _
                                                   ByVal cIntJerarquia As String, _
                                                   ByVal nSisGruCodigo As Long, _
                                                   ByVal nSisGruTipo As Long, _
                                                   ByVal nObjTipo As Long, _
                                                   Optional ByVal nIntTipo As Long = 1007) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Get_Interface")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                If nIntTipo <> -1 Then Db.AddInParameter(Cmd, "nIntTipo", System.Data.DbType.Int32, nIntTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_PerUsuGruAcc_Periodo(ByVal cPerCodigo As String, _
                                                 ByVal nSisGruCodigo As Long, _
                                                 ByVal nSisGruTipo As Long, _
                                                 Optional ByVal nPrdActividad As Integer = 2) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Get_Periodo")
                Db.AddInParameter(Cmd, "nTipo", System.Data.DbType.String, 0)
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nPrdActividad", System.Data.DbType.Int32, nPrdActividad)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_PerUsuGruAcc_UniOrg(ByVal cPerCodigo As String, _
                                                ByVal cIntJerarquia As String, _
                                                ByVal nSisGruCodigo As Long, _
                                                ByVal nSisGruTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Get_UniOrg")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_PerUsuGruAcc_Insert(ByVal cPerCodigo As String, _
                                                ByVal nSisGruCodigo As Long, _
                                                ByVal nSisGruTipo As Long, _
                                                ByVal nObjCodigo As Long, _
                                                ByVal nObjTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Set")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, nObjCodigo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_PerUsuGruAcc_Delete(ByVal cPerCodigo As String) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Del")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, Nothing)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_PerUsuGruAcc_Delete(ByVal cPerCodigo As String, _
                                                ByVal nSisGruTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Del")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, Nothing)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_PerUsuGruAcc_Delete(ByVal cPerCodigo As String, _
                                ByVal nSisGruCodigo As Long, _
                                ByVal nSisGruTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Del")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, Nothing)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_PerUsuGruAcc_Delete(ByVal cPerCodigo As String, _
                                ByVal nSisGruCodigo As Long, _
                                ByVal nSisGruTipo As Long, _
                                ByVal nObjTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Del")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_PerUsuGruAcc_Delete(ByVal cPerCodigo As String, _
                                ByVal nSisGruCodigo As Long, _
                                ByVal nSisGruTipo As Long, _
                                ByVal nObjCodigo As Long, _
                                ByVal nObjTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_PerUsuGruAcc_Del")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, nObjCodigo)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function
        Public Function Get_Info_Alumno(ByVal cPerCodigo As String) As DbCommand
            Try
                Using Cmd As DbCommand = Db.GetStoredProcCommand("SpWeb_Get_Info_Alumno")
                    Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                    Return Cmd
                End Using
            Catch ex As Exception
                Return Nothing
            End Try
        End Function

        Public Function Get_MenuPrincipal_Left(ByVal cintjerarquia As String) As DbCommand
            Try
                Dim vsql As String
                vsql = "select cintnombre,cintdescripcion,'../imagenes/menu' +cast(nIntCodigo as nvarchar(20))+'.gif' as logo  from interface where nintclase=1011 and ninttipo<>0 and cintjerarquia like '" & cintjerarquia.ToString & "%' and cintjerarquia<>'" & cintjerarquia.ToString & "' order by cintjerarquia"
                Using Cmd As DbCommand = Db.GetSqlStringCommand(vsql.ToString)
                    Return Cmd
                End Using
            Catch ex As Exception
                Return Nothing
            End Try
        End Function



        Public Function Get_UniOrg_PerJur_By_PUGA(ByVal cPerCodigo As String, _
                                                 ByVal cIntJerarquia As String, _
                                                 ByVal cSisGruCodigo As String, _
                                                 ByVal nSisGruTipo As Long) As DbCommand
            Try
                Dim cmd As DbCommand = Db.GetStoredProcCommand("sp_UniOrg_Get_PerJur_By_PUGA")
                Db.AddInParameter(cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(cmd, "cIntJerarquia", System.Data.DbType.String, cIntJerarquia)
                Db.AddInParameter(cmd, "cSisGruCodigo", System.Data.DbType.String, cSisGruCodigo)
                Db.AddInParameter(cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Return cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Get_Permiso_Disponible_Periodos_By_Per(ByVal cPerCodigo As String, _
                                                   ByVal nSisGruCodigo As Long, _
                                                   ByVal nSisGruTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("usp_Permiso_Disponible_Prd_Get_By_Per")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.String, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)

                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

        Public Function Set_PerUsuGruAcc_Prd_Delete(ByVal cPerCodigo As String, _
                                ByVal nSisGruCodigo As Long, _
                                ByVal nSisGruTipo As Long, _
                                ByVal nObjTipo As Long) As DbCommand
            Try
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("usp_PerUsuGruAcc_Prd_Del")
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "nSisGruCodigo", System.Data.DbType.Int32, nSisGruCodigo)
                Db.AddInParameter(Cmd, "nSisGruTipo", System.Data.DbType.Int32, nSisGruTipo)
                Db.AddInParameter(Cmd, "nObjCodigo", System.Data.DbType.Int32, Nothing)
                Db.AddInParameter(Cmd, "nObjTipo", System.Data.DbType.Int32, nObjTipo)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function
#End Region

#Region "Transacciones"

        Public Function Set_Transaccion_Insert(ByVal Operacion As Long, _
                                               ByVal cPerCodigo As String, _
                                               ByVal RemoteHost As String, _
                                               ByVal Descripcion As String) As DbCommand
            Try
                Dim cTraCodigo As String = String.Empty
                Dim Cmd As DbCommand = Db.GetStoredProcCommand("sp_Transaction_Set")
                cTraCodigo = Format(Date.Now, "WEByyyyMMddhhmmssFF")
                Db.AddInParameter(Cmd, "cTraCodigo", System.Data.DbType.String, cTraCodigo)
                Db.AddInParameter(Cmd, "nOpeCodigo", System.Data.DbType.Int32, Operacion)
                Db.AddInParameter(Cmd, "cPerCodigo", System.Data.DbType.StringFixedLength, cPerCodigo)
                Db.AddInParameter(Cmd, "cTraHost", System.Data.DbType.String, RemoteHost)
                Db.AddInParameter(Cmd, "cTraDescripcion", System.Data.DbType.String, Descripcion)
                Return Cmd
            Catch ex As DbException
                Throw ex
            End Try
        End Function

#End Region

#End Region

    End Class

End Namespace

